<?php

namespace App\Models\ActivityDB\ValentinesDayNetwork;

use Illuminate\Database\Eloquent\Model;

class VdUserScore extends Model
{
    protected $table = 'ac_valen_network_user_score';
    public $connection = 'mysql_activity';

    public $timestamps = false;
    protected $fillable = ['id',           //主键ID
        'user_id',      //用户ID
        'score',    //分数变更
        'change_type',    //签到类型
        'product_id',    //兑换商品id
        'product_num',    //礼物数量
        'is_add_score',    //是否添加积分
    ];

    public function updateUserScore($user_id,$score,$change_type=1,$product_id=0)
    {
        $data = [
            'user_id' => $user_id,
            'score' => $score,
            'change_type' => $change_type,
            'product_id' => $product_id,
        ];
        $this->create($data);
        return app('model_valentines_network_user')->where('user_id', $user_id)->increment('score', $score);
    }

}
